package com.haiyou.dc.api.controller;

import com.haiyou.common.util.R;
import com.haiyou.mini.programs.service.WxMiniAppService;
import com.haiyou.oss.alibaba.service.AliOSSService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.InputStream;

/**
 * @author root
 * @date 2019-10-02 12:37:01
 */
@RestController
@RequestMapping("/open/wx/qrcode")
@Slf4j
@Api(tags = "小程序二维码接口")
public class WxCodeApi {

    @Autowired
    private WxMiniAppService wxMiniAppService;
    @Autowired
    private AliOSSService aliYunOSSService;

    @ApiOperation(value = "生成二维码")
    @GetMapping("/createQrCode/{userId}")
    public R createQrCode(@ApiParam(value = "用户编号", required = true) @PathVariable("userId") String userId) {
        InputStream qrCodeInputStream = wxMiniAppService.createQRCode(userId);
        String qRCode = aliYunOSSService.upLoad(qrCodeInputStream);
        return R.ok(qRCode);
    }

}